#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
 
typedef struct LNode
{
    char data;
    struct LNode *next;
} LNode,*LinkList;

int Create_Linklist(LinkList& p)
{
    LinkList t,head;
    int n;
    cin>>n;
    head=p;
    for(int i=0;i<n;i++){
        t=(LinkList)malloc(sizeof(LNode));
        cin>>t->data;
        head->next=t;
        head=head->next;
    }
    head->next=p;
    return n;
}
void Print_Linklist(LinkList p)
{
    LinkList head=p->next;
    while(head!=p){
        if(head->next==p){
        	cout<<head->data;
		}
        else{
        	cout<<head->data<<" ";
		}
        head=head->next;
    }
}
int Get_Length(LinkList p){
    int cnt=0;
    LinkList head=p->next;
    while(head!=p){
        cnt++;
        head=head->next;
    }
    return cnt;
}
char Get_Element(LinkList p){
    int cnt=1;
    char e;
    int temp=3;
    if(Get_Length(p)<temp)temp=Get_Length(p);
    LinkList head=p->next;
    while(true){
        if(cnt==temp){
            e=head->data;
            return e;
        }
        cnt++;
        head=head->next;
    }
}
int Get_Count(LinkList p,char e){
    int cnt=1;
    LinkList head=p->next;
    while(head!=p){
        if(head->data==e){
            return cnt;
        }
        cnt++;
        head=head->next;
    }
    return 0;
}
void Insert_Linklist(LinkList& p,int pos,char e){
    if(pos<=0||Get_Length(p)<pos-1)return;
    int cnt=2;
    LinkList head=p->next,t;
    while(head!=p){
        if(cnt==pos){
            t=(LinkList)malloc(sizeof(LNode));
            t->data=e;
            t->next=head->next;
            head->next=t;
        }
        cnt++;
        head=head->next;
    }
}
void Delete_Linklist(LinkList& p,int pos){
    if(pos<=0||Get_Length(p)<pos)return;
    int cnt=2;
    LinkList head=p->next;
    while(head!=p){
        if(cnt==pos){
            LinkList t=head->next;
            head->next=t->next;
            free(t);
            break;
        }
        cnt++;
        head=head->next;
    }
 
}
void List_free(LinkList& p)
{
    LinkList head,rear;
    head=p->next;
    while(head!=p){
        rear=head;
        head=head->next;
        free(rear);
    }
}
char e;
int cnt;
int main()
{
    LinkList l;
    l=(LinkList)malloc(sizeof(LNode));
    l->next=l;
    if(l->next==l){
    	cout<<1<<endl;
	}else{
    	cout<<0<<endl;
	}
    cnt=Create_Linklist(l);
    Print_Linklist(l);
    	cout<<endl;
    	cout<<cnt<<endl;
    if(l->next==l){
    	cout<<"yes"<<endl;
	}
    else {
    	cout<<"no"<<endl;
	}
    e=Get_Element(l);
    	cout<<e<<endl;
    cnt=Get_Count(l,'a');
    	cout<<cnt<<endl;
    Insert_Linklist(l,4,'w');
    Print_Linklist(l);
    	cout<<endl;
    Delete_Linklist(l,5);
    Print_Linklist(l);
    List_free(l);
}
